package com.gaogzhen.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.gaogzhen.domain.AdminBank;
import com.gaogzhen.dto.AdminBankDto;
import com.gaogzhen.feign.AdminBankServiceFeign;
import com.gaogzhen.service.AdminBankService;
import com.gaogzhen.utils.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import java.util.List;

/**
 * @author Administrator
 * @version 1.0
 * @description 公司银行卡管理
 * @date 2022-06-06 10:47
 */
@RestController
@RequestMapping("/adminBanks")
@Api(tags = "公司银行卡管理")
public class AdminBankController implements AdminBankServiceFeign {

    @Autowired
    private AdminBankService adminBankService;

    @GetMapping
    @ApiOperation("分页查询公司银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "size", value = "每页大小"),
            @ApiImplicitParam(name = "bankCard", value = "银行卡号"),
    })
    @PreAuthorize("hasAuthority('admin_bank_query')")
    public R<Page<AdminBank>> findByPage(@ApiIgnore Page<AdminBank> page, String bankCard) {
        return R.ok(adminBankService.findByPage(page, bankCard));
    }

    @PostMapping
    @ApiOperation("新增adminBank")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminBank", value = "银行卡信息")
    })
    @PreAuthorize("hasAuthority('admin_bank_create')")
    public R add(@RequestBody @Validated AdminBank adminBank) {
        adminBankService.add(adminBank);
        return R.ok();
    }

    @PatchMapping
    @ApiOperation("修改公司银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminBank", value = "银行卡信息")
    })
    @PreAuthorize("hasAuthority('admin_bank_update')")
    public R update(@RequestBody @Validated AdminBank adminBank) {
        adminBankService.updateBank(adminBank);
        return R.ok();
    }

    @PatchMapping("/updateBankStatus")
    @ApiOperation("启用禁用公司银行卡")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "bankId", value = "银行卡id"),
            @ApiImplicitParam(name = "status", value = "银行卡状态"),
    })
    @PreAuthorize("hasAuthority('admin_bank_update')")
    public R updateBankStatus(Long bankId, Integer status) {
        adminBankService.updateBankStatus(bankId, status);
        return R.ok();
    }

    @Override
    public List<AdminBankDto> getAllAdminBanks() {
        return adminBankService.getAllAdminBanks();
    }
}
